package thread;

/**
 * 优先级设置
 * @Author Janson
 * @Date 2022/2/27 12:56
 * @Version 1.0
 */
public class TestThreadPriority implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+
                    "线程的优先级为:"+
                    Thread.currentThread().getPriority()+"执行次数" + i);
        }
    }
    public static void main(String[] args) {
        TestThreadPriority testThreadPriority = new TestThreadPriority();
        //线程1
        Thread thread1 = new Thread(testThreadPriority,"1线程");
        thread1.setPriority(Thread.MAX_PRIORITY);
        thread1.start();
        //线程2
        Thread thread2 = new Thread(testThreadPriority,"2线程");
        thread2.setPriority(8);
        thread2.start();
        //线程3
        Thread thread3 = new Thread(testThreadPriority,"3线程");
        thread3.setPriority(4);
        thread3.start();
        //线程4
        Thread thread4 = new Thread(testThreadPriority,"4线程");
        thread4.setPriority(1);
        thread4.start();
        //线程5
        Thread thread5 = new Thread(testThreadPriority,"5线程");
        thread5.setPriority(6);
        thread5.start();
        System.out.println("main线程的优先级为：" + Thread.currentThread().getPriority());
    }
}
